package de.koller.million.card.engine.item;

import de.koller.million.card.CNode;
import de.koller.million.card.engine.util.Utils;

public class NormalSpawn extends CNode {

	public static final double DAMAGE_ILVL_FACT = 1.2;
	
	public static Item getBest( ItemQuality quality, ItemSlot slot, int ilvl ) {
		PropertySetItem i = new PropertySetItem( -1 );
		i.setQuality( quality );
		i.setSlot( slot );
		i.setIlvl( ilvl );
		
		i.setDamage( DAMAGE_ILVL_FACT );

		return i;
	}
	
	public Item createItem( long id, int tier ) {
		PropertySetItem i = new PropertySetItem( id );
		i.setQuality( getQuality() );
		i.setSlot( getSlot() );
		int ilvl = getIlvl( tier );
		i.setIlvl( ilvl );
		
		i.setDamage( DAMAGE_ILVL_FACT );
		return i;
	}
	
	private ItemQuality getQuality() {
		int r = Utils.prop( croot.rnd, 2, 20, 34, 44 );
		if( r == 0 ) return ItemQuality.Better;
		if( r == 1 ) return ItemQuality.Common;
		if( r == 2 ) return ItemQuality.Normal;
		return  ItemQuality.Poor;
	}
	
	private int getIlvl( int tier ) {
		int r = Utils.prop( croot.rnd, 3, 5, 2 );
		if( r == 0 ) return tier + 1;
		if( r == 1 ) return tier;
		return tier - 1;
	}
	
	private ItemSlot getSlot() {
		int r = croot.rnd.nextInt( ItemSlot.values().length );
		return ItemSlot.values()[r];
	}
	
}
